import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * DataTable
 * @date 2019-08-21
 */
import React, { Component } from 'react';
import { Table } from 'antd';
import intl from 'utils/intl';
import { tableScrollWidth } from 'utils/utils';
import { dateTimeRender, operatorRender, TagRender } from 'utils/renderer';

var DataTable = /*#__PURE__*/function (_Component) {
  _inherits(DataTable, _Component);

  var _super = _createSuper(DataTable);

  function DataTable() {
    _classCallCheck(this, DataTable);

    return _super.apply(this, arguments);
  }

  _createClass(DataTable, [{
    key: "getColumns",
    value: function getColumns() {
      var _this = this;

      return [{
        title: intl.get('cimp.commentImport.model.commentImport.batch').d('批次号'),
        dataIndex: 'batch'
      }, {
        title: intl.get('cimp.commentImport.model.commentImport.dataCount').d('数据数量'),
        dataIndex: 'dataCount',
        width: 100
      }, {
        title: intl.get('cpaas.common.status').d('状态'),
        dataIndex: 'status',
        width: 130,
        render: function render(status) {
          var _this$props$dataImpor = _this.props.dataImportStatus,
              dataImportStatus = _this$props$dataImpor === void 0 ? [] : _this$props$dataImpor;
          var statusList = [{
            status: 'UPLOADING',
            color: 'blue'
            /* , text: 'Excel导入' */

          }, {
            status: 'UPLOADED',
            color: 'green'
            /* , text: '验证成功' */

          }, {
            status: 'CHECKING',
            color: 'blue'
            /* , text: '验证失败' */

          }, {
            status: 'CHECKED',
            color: 'green'
            /* , text: '导入成功' */

          }, {
            status: 'IMPORTING',
            color: 'blue'
            /* , text: '导入失败' */

          }, {
            status: 'IMPORTED',
            color: 'green'
            /* , text: '数据异常' */

          }];
          return TagRender(status, dataImportStatus.map(function (item) {
            var tagItem = statusList.find(function (t) {
              return t.status === item.value;
            }) || {};
            return {
              status: item.value,
              text: item.meaning,
              color: tagItem.color
            };
          }));
        }
      }, {
        title: intl.get('cimp.commentImport.model.commentImport.creationDate').d('创建日期'),
        dataIndex: 'creationDate',
        width: 160,
        render: dateTimeRender
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        key: 'operator',
        width: 110,
        render: function render(_, record) {
          // TODO: 操作逻辑
          var _this$props = _this.props,
              onRecordRestore = _this$props.onRecordRestore,
              onRecordDelete = _this$props.onRecordDelete;
          var operators = [{
            key: 'restore',
            ele: /*#__PURE__*/React.createElement("a", {
              onClick: function onClick() {
                onRecordRestore(record);
              }
            }, intl.get('cimp.commentImport.view.button.restore').d('恢复')),
            len: 2,
            title: intl.get('cimp.commentImport.view.button.restore').d('恢复')
          }];

          if (['IMPORTED', 'CHECKED', 'UPLOADED'].includes(record.status)) {
            operators.push({
              key: 'delete',
              ele: /*#__PURE__*/React.createElement("a", {
                onClick: function onClick() {
                  onRecordDelete(record);
                }
              }, intl.get('cpaas.common.button.delete').d('删除')),
              len: 2,
              title: intl.get('cpaas.common.button.delete').d('删除')
            });
          }

          return operatorRender(operators, record);
        }
      }];
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          _this$props2$dataSour = _this$props2.dataSource,
          dataSource = _this$props2$dataSour === void 0 ? [] : _this$props2$dataSour,
          _this$props2$paginati = _this$props2.pagination,
          pagination = _this$props2$paginati === void 0 ? false : _this$props2$paginati,
          onChange = _this$props2.onChange,
          _this$props2$queryLoa = _this$props2.queryLoading,
          queryLoading = _this$props2$queryLoa === void 0 ? false : _this$props2$queryLoa,
          _this$props2$deleteLo = _this$props2.deleteLoading,
          deleteLoading = _this$props2$deleteLo === void 0 ? false : _this$props2$deleteLo;
      var columns = this.getColumns();
      return /*#__PURE__*/React.createElement(Table, {
        loading: queryLoading || deleteLoading,
        bordered: true,
        rowKey: "batch",
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        dataSource: dataSource,
        pagination: pagination,
        onChange: onChange
      });
    }
  }]);

  return DataTable;
}(Component);

export default DataTable;